# 排班管理页面测试
import unittest
from Lib.base.page_object.duty.duty_manager_add import DutyManagerAdd
from Lib.base.page_object.duty.duty_manager_list import DutyManagerList
from selenium.webdriver.common.by import By
from Lib.common.ui_log import error_log, normal_log
import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestDutyManager.assertClass = AssertClass(login)
    TestDutyManager.dutyManager = DutyManagerAdd(login)
    TestDutyManager.dutyManagerList = DutyManagerList(login)


@allure.feature('排班管理页面测试')
class TestDutyManager:

    @allure.title('新增排班')
    def test_1_duty_add(self):
        '''
        新增排班
        :return:
        '''
        self.dutyManager.add_duty()
        # 设置断言
        assert_arg = (By.XPATH, '//p[text()="新增成功"]')
        self.assertClass.make_assert_by_text(args=assert_arg, assert_data='新增成功', context='新增排班')

    @allure.title('排班列表查询')
    def test_2_duty_list(self):
        '''
        排班列表
        :return:
        '''
        self.dutyManagerList.duty_list()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "暂无数据")]')
        self.assertClass.make_assert_by_text(args=assert_arg, assert_data='暂无数据', context='排班列表')

    @allure.title('排班查询和修改')
    def test_3_duty_list_update(self):
        '''
        排班列表 和修改
        :return:
        '''
        self.dutyManagerList.duty_list_update()
        assert_arg = (By.XPATH, '//p[contains(text(), "修改成功")]')
        self.assertClass.make_assert_by_text(args=assert_arg, assert_data='修改成功', context='排班列表')

    @allure.title('排班查询和删除')
    def test_4_duty_list_delete(self):
        '''
        排班列表 和删除
        :return:
        '''
        self.dutyManagerList.duty_list_delete()
        assert_arg = (By.XPATH, '//p[contains(text(), "删除成功")]')
        self.assertClass.make_assert_by_text(args=assert_arg, assert_data='删除成功', context='排班列表')


if __name__ == '__main__':
    pytest.main(['-v', './duty_manager_test.py'])

